package dfs;

import java.util.ArrayList;
import java.util.List;

public class LexicographicalNumbers386 {
    public List<Integer> lexicalOrder(int n) {
        List<Integer> result = new ArrayList<>();
        for (int i = 1; i < 10; i++) {
            dfs(result,i,n);
        }
        return result;
    }

    private void dfs(List<Integer> result,int cur,int max){
        if(cur>max){
            return;
        }
        result.add(cur);
        for (int i = 0; i < 10; i++) {
            dfs(result,cur*10+i,max);
        }
    }

}
